<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class CustomerReport extends CI_Controller {
 function __construct()
 {
   parent::__construct();
   $this->load->model('muser');
   $this->load->library('form_validation');
   $this->load->library('pagination');  
  $this->load->library('my_lab');
  $this->load->library('my_time');
  $this->load->library('my_datatables');  
 }
 function index(){
	if ($this->input->post('Lab_ID'))
	{
		$Lab_ID=$this->input->post('Lab_ID');
		$FromDate=$this->input->post('FromDate');
		$ToDate=$this->input->post('ToDate');
		$type=$this->input->post('type');
		if ($type=='OverTime')
		{
			$OverTime_ID=$this->input->post('OverTime');
			$result=$this->my_lab->getLabSalary($Lab_ID,$OverTime_ID,$FromDate,$ToDate);
			}
		else if($type='Percent')
		{
			$Percent=$this->input->post('Percent');
			$Percent=$Percent/100;
			$result=$this->my_lab->makeLabPercent($Lab_ID,$Percent,$FromDate,$ToDate);
			
		}	
		if ($result==FALSE) echo "tinh salary khong thanh cong";
		$result=$this->muser->getLabSalary($Lab_ID,$FromDate,$ToDate);
		
		$data['result']=$result;
		$data['FromDate']=$FromDate;
		$data['ToDate']=$ToDate;
		$data['Lab_ID']=$Lab_ID;
		$this->load->view('_header');
      	$this->load->view('customerReport/customerReport_view',$data); 
        $this->load->view('_footer');	
        			
      }
	else{
		$data['lab']=$this->getLabID();			
		$this->load->view('_header');
      	$this->load->view('customerReport/customerReport_view',$data); 
        $this->load->view('_footer');
	}		 	
	
 }
function getLabID()
	{
	$project1=$this->muser->getData('Lab');
	if ($project1 !='0'){
		 foreach ($project1 as $row) 
			 {
				 $project[$row->Lab_ID]=$row->Lab_ID.'-'.$row->LabName;
			 }
		 return $project;
	}
		
	}
	
	
function allLab(){
	$this->load->view('_header');
	$this->load->view('customerReport/allLab_view');
	$this->load->view('_footer');
	
	}

function table(){
	$this->my_datatables
 		->select('Lab_ID ,CustomerReport.Staff_ID, FullName, FromDate,ToDate,BasicSalary,ActSalary,OTSalary,PaySalary')
		->from('CustomerReport')
		->join('Staff','Staff.Staff_ID=CustomerReport.Staff_ID');
		//->select('FullName');
	echo $this->my_datatables->generate();
}		

}
